#include <stdio.h>
#include "Array_Function.h"
#include "Text_Function.h"
#include "Record_NodeList.h"

int main() {

    char Test_Array[32][32] = {"date", "time", "open", "close", "price"};
    char* Test_String = "Name,Date,Code,Open,High,Low,Close";
    char** Test_Char_PtrArray;
    /* ********************************************** */
    /* 测试: 字符数组 - 通过字符串获得下标索引 (Char Array - Get Index by String) */
    printf("Test: Char Array - Get Index by String: %d\n", Char_Array_Get_Index_By_String(Test_Array, "price"));
    /* ********************************************** */
    /* 测试: 字符数组 - 判断存在某个字符串 (Char Array - Judge Exists String) */
    printf("Test: Char Array - Judge Exists String: %d\n", Char_Array_Judge_Exists_String(Test_Array, "Date"));
    /* ********************************************** */
    /* 测试: 字符指针数组 - 通过字符串获得下标索引 (Char PtrArray - Get Index by String) */
    printf("Test: Char PtrArray - Get Index by String: %d\n", Char_PtrArray_Get_Index_By_String(*Test_Array, "close"));
    /* ********************************************** */
    /* 测试: 字符指针数组 - 分割字符串到指针数组 (Char PtrArray - Split String to PtrArray) */
    Test_Char_PtrArray = Char_PtrArray_Split_String_To_PtrArray(Test_String, ",");
    printf("Test: Char PtrArray - Split String to PtrArray: %s\n", Test_Char_PtrArray[0]);
    /* ********************************************** */
    /* 测试: CSV - 获取Csv总行数 */
    printf("Test: Csv - Get Rows Total Number: %d\n", Csv_Get_Rows_Total_Num(".\\Test_NDSD_300750_GB2312.csv"));
    /* ********************************************** */
    /* 测试: CSV - 获取Csv总列数 */
    printf("Test: Csv - Get Cols Total Number: %d\n", Csv_Get_Cols_Total_Num(".\\Test_NDSD_300750_GB2312.csv"));
    /* ********************************************** */
    /* 测试: CSV - 首行读取为指针数组(PtrArray) */
    Test_Char_PtrArray = Csv_First_Row_Read_As_PtrArray(".\\Test_NDSD_300750_GB2312.csv");
    printf("Test: Csv - First Row Read as PtrArray: %s\n", Test_Char_PtrArray[6]);
    /* ********************************************** */
    /* 测试: CSV - 读取为CsvString */
    char* CsvString = Csv_Read_As_CsvString(".\\Test_NDSD_300750_GB2312.csv");
    //printf("Test: Csv - Read as CsvString:\n%s\n", CsvString);
    /* ********************************************** */
    /* 测试: CSV - 读取为二维指针数组(TwoDimPtrArray) */
    char*** CsvPtrArray = Csv_Read_As_TwoDimPtrArray(".\\Test_NDSD_300750_GB2312.csv");
    printf("Test: Csv - Read as TwoDimPtrArray: %s\n", CsvPtrArray[514][0]);
    /* ********************************************** */
    /* 测试: 二维字符指针数组 - 获取行数 (Char TwoDimPtrArray - Get Rows Number) */
    printf("Test: Char TwoDimPtrArray - Get Rows Number: %lld\n", Char_TwoDimPtrArray_Get_RowsNum(CsvPtrArray));
    /* ********************************************** */
    /* 测试: CSV - CsvString清洗 - 指针移动法 */
    char* Washed_By_Pointer_Mov_CsvString = Csv_CsvString_Wash_By_Pointer_Mov(CsvString);
    //printf("Test: Csv - CsvString Wash By Pointer Mov:\n%s\n", Washed_By_Pointer_Mov_CsvString);
    /* ********************************************** */
    /* 测试: CSV - CsvString清洗 - Sscanf过滤法 */
    char* Washed_By_Sscanf_CsvString = Csv_CsvString_Wash_By_Sscanf(CsvString);
    //printf("Test: Csv - CsvString Wash By Sscanf:\n%s\n", Washed_By_Sscanf_CsvString);
    /* ********************************************** */
    /* 测试: Record NodeList */
    printf("Test: Record NodeList:\n");
    struct Record_Node* Fin_Record_Head = Record_NodeList_Node_Init();
    Field_NodeList_Append_Field(Fin_Record_Head->Field, "Date");
    Field_NodeList_Append_Field(Fin_Record_Head->Field, "Close");
    Field_NodeList_Append_Field(Fin_Record_Head->Field, "Volume");
    Record_NodeList_Load_FldVal_From_TwoDimPtrArr(Fin_Record_Head, "Date", CsvPtrArray, 0);
    Record_NodeList_Load_FldVal_From_TwoDimPtrArr(Fin_Record_Head, "Close", CsvPtrArray, 1);
    Record_NodeList_Load_FldVal_From_TwoDimPtrArr(Fin_Record_Head, "Volume", CsvPtrArray, 5);
    Record_NodeList_Delete_Record_By_Idx(Fin_Record_Head, 0);
    Record_NodeList_Reset_Record_Idx(Fin_Record_Head);
    Record_NodeList_FldVal_Type_Convert(Fin_Record_Head, "Close", "Decimal");
    Record_NodeList_Bubble_Sort_Asc_By_FldName(Fin_Record_Head, "Close");

    struct Record_Node* Right_Record_Head = Record_NodeList_Node_Init();
    Field_NodeList_Append_Field(Right_Record_Head->Field, "Date");
    Field_NodeList_Append_Field(Right_Record_Head->Field, "Open");
    Record_NodeList_Load_FldVal_From_TwoDimPtrArr(Right_Record_Head, "Date", CsvPtrArray, 0);
    Record_NodeList_Load_FldVal_From_TwoDimPtrArr(Right_Record_Head, "Open", CsvPtrArray, 2);

    struct Record_Node* New_Record_Head = Record_NodeList_Left_Join_On_RecIdx(Fin_Record_Head, Right_Record_Head, "(2)");
    //struct Record_Node* New_Record_Head = Record_NodeList_Left_Join_On_FldName(Fin_Record_Head, Right_Record_Head, "Date");
    Record_NodeList_Record_Format_Print(New_Record_Head);

    return 0;
}
